import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'

//消除跨域警告
process.env["ELECTRON_DISABLE_SECURITY_WARNINGS"] = "true";
export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()]
  },
  preload: {
    plugins: [externalizeDepsPlugin()]
  },
  renderer: {
    resolve: {
      alias: {
        '@renderer': resolve('src/renderer/src'),
        //增加路径别名
        '@store': resolve('src/renderer/src/store'),
        '@views': resolve('src/renderer/src/views'),
        '@router': resolve('src/renderer/src/router'),
        '@components': resolve('src/renderer/src/components'),
        '@utils': resolve('src/renderer/src/utils'),
        '@api': resolve('src/renderer/src/api')
      }
    },
    plugins: [vue()],
    server: {
      // headers: {
      //    // 'Access-Control-Allow-Origin': '*', // 或者你的源地址
      //     'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
      //     'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
      // },
      // open: true,
      host: '0.0.0.0',
      port: 5173,
      proxy: {
        '/client_api': {
          target: 'https://www.huaicaikeyu.cn/client_api', //访问地址
          changeOrigin: true,
          secure: true,
          rewrite: (path) => path.replace(/^\/client_api/, '')
        },
        // '/activity': {
        //   target: 'https://baijiahao.baidu.com/activity', //访问地址
        //   changeOrigin: true,
        //   secure: true,
        //   rewrite: (path) => path.replace(/^\/activity/, ''),
        //   cookieDomainRewrite: {
        //     'https://baijiahao.baidu.com': 'localhost'
        //   }
        // },
        // '/pcui': {
        //   target: 'https://baijiahao.baidu.com/pcui', // 上传图片、发布
        //   changeOrigin: true,
        //   // secure: true,
        //   rewrite: (path) => path.replace(/^\/pcui/, ''),
        //   bypass(req, res, options) {
        //     //@ts-ignore
        //     const proxyUrl = new URL(options.rewrite(req.url) || '',(options.target)as string)?.href || '';
        //     console.log(proxyUrl);
        //     req.headers['x-req-proxyUrl'] = proxyUrl
        //     res.setHeader('x-res-proxyUrl',proxyUrl)
        //   },
        // }
      },
    },
  }
})
